package com.bawei.park2301.notice

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.bawei.libs_base.entity.NoticeBeanItem
import com.bawei.park2301.R
import com.bawei.park2301.databinding.ItemNoticeBinding

class NoticeAdapter: PagingDataAdapter<NoticeBeanItem, NoticeAdapter.NoticeViewHolder>(differ) {

    companion object {
        val differ= object : DiffUtil.ItemCallback<NoticeBeanItem>() {
            override fun areContentsTheSame(
                oldItem: NoticeBeanItem,
                newItem: NoticeBeanItem
            ): Boolean {
                return oldItem == newItem
            }

            override fun areItemsTheSame(
                oldItem: NoticeBeanItem,
                newItem: NoticeBeanItem
            ): Boolean {
                return oldItem.id == newItem.id
            }

        }
    }

    class NoticeViewHolder(view: View):ViewHolder(view){
        val binding=DataBindingUtil.bind<ItemNoticeBinding>(view)
    }

    override fun onBindViewHolder(holder: NoticeViewHolder, position: Int) {
        holder.binding?.notice=getItem(position)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NoticeViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_notice, parent, false)
        return NoticeViewHolder(view)
    }
}